package com.hnust.service.impl;

import com.hnust.dao.CollegeAdminDao;
import com.hnust.dao.CollegeDao;
import com.hnust.domain.College;
import com.hnust.domain.CollegeAdmin;
import com.hnust.domain.record.CollegeAdminRecord;
import com.hnust.service.CollegeAdminService;
import com.hnust.util.IDUtil;
import com.hnust.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *创建人：王月阳
 *创建时间：2020/10/6
 *描述：校管理员-院管理员设置模块
 *token判断在controller层
 */
@Service("collegeAdminService")
public class CollegeAdminServiceImpl implements CollegeAdminService {

    @Autowired
    private CollegeAdminDao collegeAdminDao;

    /**
     * 获取院管理员信息
     * @return
     */
    public Boolean addCollegeAdmin(CollegeAdminRecord collegeAdminRecord) {
        try{
            //生成院管理员id
            String collegeAdminId = IDUtil.getPrimaryKey();

            String name  = collegeAdminRecord.getName();
            String account = collegeAdminRecord.getAccount();               //不能与其他院管理员重复
            String password = collegeAdminRecord.getPassword();
            String collegeId = collegeAdminRecord.getCollegeId();

            return collegeAdminDao.addCollegeAdmin(collegeAdminId,account,password,name,collegeId);
        }catch (Exception e){
            return false;
        }

    }

    @Override
    public List<CollegeAdminRecord> getCollegeAdmin() {
        try{
            //获取Dao层的院管理员信息
            List<CollegeAdminRecord> collegeAdminRecords=collegeAdminDao.getCollegeAdmin();
            return collegeAdminRecords;
        }catch (Exception e){
            return null;
        }

    }

    /**
     * 删除单个院管理员信息
     * @param collegeAdminId 院管理员id
     * @return
     */
    @Override
    public Boolean deleteCollegeAdmin(String collegeAdminId) {
        try{
            //获取Dao层的院管理员id
            Boolean del = collegeAdminDao.deleteCollegeAdmin(collegeAdminId);
            return del;
        }catch (Exception e){
            return false;
        }

    }

    /**
     * 批量删除院管理员信息
     * @param collegeAdminIds 所有院管理员id
     * @return
     */
    @Override
    public Boolean bathDeleteCollegeAdmin(List<String> collegeAdminIds) {
        try {
            return collegeAdminDao.batchDeleteCollegeAdmin(String.join(",",collegeAdminIds)) == collegeAdminIds.size();
        }catch (Exception e){
            return false;
        }
    }

    /**
     * 修改院管理员信息
     * @param collegeAdminRecord 院管理员的对象信息
     * @return
     */
    @Override
    public Boolean modifyCollegeAdmin(CollegeAdminRecord collegeAdminRecord) {
        try {
            //获取到对象中的姓名，账号，密码，id，作为参数传给dao层
            String name  = collegeAdminRecord.getName();
            String account = collegeAdminRecord.getAccount();               //不能与其他院管理员重复
            String password = collegeAdminRecord.getPassword();
            String collegeAdminId = collegeAdminRecord.getCollegeAdminId(); //不可以修改
            String collegeId = collegeAdminRecord.getCollegeId(); //不可以修改

            return collegeAdminDao.modifyCollegeAdmin(name,account,password,collegeAdminId,collegeId);
        }catch (Exception e){
            return false;
        }

    }
}
